package com.sskj.b70.p.activity;

import com.lzy.okgo.model.Response;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.Entrust;
import com.sskj.b70.m.bean.HaiPageBean;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.v.activity.EntrustActivity;

/**
 * Created by Administrator on 2018/5/2.
 */

public class EntrustPresenter extends BasePresenter<EntrustActivity> {


    /**
     * 获取全部交易列表
     *
     * @param
     * @param
     */
    public void getEntrustList() {
        httpService.getCoinEntrustingList(null)
                .execute(new JsonCallBack<HttpData<HaiPageBean<Entrust>>>() {
                    @Override
                    public void _onSuccess(Response<HttpData<HaiPageBean<Entrust>>> response) {
                        if (response.body() != null) {
                            if (response.body().getStatus() ==HttpConfig.STATUS_OK) {
                                mView.setData(response.body().getData().getRes());
                            }
                        }
                    }
                });

    }

    /**
     * 撤销订单
     *
     * @param
     * @param order_id 订单号
     */
    public void cancelOrder(int tradeType, String order_id) {
        httpService.cancelCoinOrder(tradeType,order_id)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<String>> response) {
                        if (response.body() != null) {
                            if (response.body().getStatus() ==HttpConfig.STATUS_OK) {
                                mView.cancelOrder(response.body().getMsg(), true);
                            } else {
                                mView.cancelOrder(response.body().getMsg(), false);
                            }
                        }
                    }

                });
    }
}
